vcMotionController

Motion controller is a behavior that is used to control motion of a mechanism through associated vcLinkJoints.

See in: Overview

Module: vcRobotics2

Parent: vcBehavior

Children -

Referenced by: vcControllerGroup.Controllers, vcJointDriver.ActiveController, vcJointDriver.OwnerController, vcSimJointDriverExportField.Controller, ... (see more)
vcControllerGroup.Controllers
vcJointDriver.ActiveController
vcJointDriver.OwnerController
vcSimJointDriverExportField.Controller
vcSingleDofLinkJoint.Controller

Properties

Learn how to use properties here. The properties are also inherited from the parent class.

NameTypeAccessDescription
DriverCountIntegerRGets the number of internal drivers.
DriverPositionslist[Real]RWGets or sets a list of internal driver positions.
DriversvcList[vcJointDriver]RGets all internal drivers in their indexed order.
ExternalDriverCountIntegerRGets the number of external drivers.
ExternalDriverPositionslist[tuple[Integer, Real]]RWGets or sets a list of external driver positions. Each item is a tuple of (int driverIndex, double driverValue).
ExternalDriversvcList[vcJointDriver]RGets a list of external drivers in the order they appear in their indexed list. Empty slots are skipped.
GroupsvcList[vcControllerGroup]RGets all controller groups created on this controller.
IsStoppedBooleanRGets the current stopped state.
KinematicsvcKinematicsRWGets or sets the vcKinematics object to use with this controller.

Methods

Learn how to use methods here. The methods are also inherited from the parent class.

NameReturn TypeParametersDescription
abortNoneNoneStops all movement (immediate) and clears the target / motion queue.

Parameters:
None

Returns:
None
addCoordinatedTargetIntegervcMotionControllerTarget targetAdds the given target to an internal queue.
See more
You can construct a target in Python with vcPtpTarget(), vcLinearTarget() or vcMultiDriverTarget().

Call moveCoordinated() after adding one or more targets to make sure motions are being processed.

If target.TargetId is a positive integer, it is taken to mean an expected targetId value. This id value must not already be in use.
If target.TargetId is zero, the next free id is automatically assigned to this target, and returned from this method call.

Parameters:
targetId (int): Identification number for the target.
driverIndex (int): Index of the driver that this target applies to.
isExternal (bool): False if this target applies to an internal driver, True if it applies to an external driver.
valueType (vcDriverTargetValueType): Determines what the 'value' parameters means.
value (float): The target value. Also see valueType.
isSynchronized (bool): If True, this target will be marked to be synchronized with other targets for which this parameter is True.
maxVelocity (float): Maximum velocity used for planning the motion. If not provided, setting in the vcJointDriver will be used.
maxAcceleration (float): Maximum acceleration used for planning the motion. If not provided, setting in the vcJointDriver will be used.
maxDeceleration (float): Maximum deceleration used for planning the motion. If not provided, setting in the vcJointDriver will be used. The value must be positive.
maxJerk (float): Maximum jerk used for planning the motion. If not provided, setting in the vcJointDriver will be used.

Returns:
int: targetId assigned to the target. If the given targetId was positive, this will always be the same value.

Exceptions:
ValueError: When targetId is a negative value.
addIndependentTargetIntegerInteger targetId,
Integer driverIndex,
Boolean isExternal,
vcDriverTargetValueType valueType,
Real value,
Boolean isSynchronized,
Optional Keyword[maxVelocity = Real],
Optional Keyword[maxAcceleration = Real],
Optional Keyword[maxDeceleration = Real],
Optional Keyword[maxJerk = Real]
Call to add an independent motion target for a specific internal or external driver into an internal buffer.
Call moveIndependent() to plan and clear all targets from this buffer.

A target can have a target value for either position or velocity, selected with the valueType parameter.

It is possible to synchronize the durations of motions resulting from selected targets. The value of "isSynchronized" will determine whether
See more
this target is included in the list of motions to synchronize - other motions will remain time optimal. The synchronization is only performed
when planning the motions and is not updated subsequently if, e.g., a new un-synchronized target is given to one of the involved drivers
before the motions have been completed.

If target.TargetId is a positive integer, it is taken to mean an expected targetId value. This id value must not already be in use unless
it was used for this same driver.
If target.TargetId is zero, the next free id is automatically assigned to this target, and returned from this method call.

An independent motion can replace a previous independent motion for the same driver. targetId does not have to be the same as that of the
previous motion but it can be.
The previous motion will be cancelled, i.e., TargetStatusChanged with 'Cancelled' eventType will be raised.

Parameters:
targetId (int): Identification number for the target.
driverIndex (int): Index of the driver that this target applies to.
isExternal (bool): False if this target applies to an internal driver, True if it applies to an external driver.
valueType (vcDriverTargetValueType): Determines what the 'value' parameters means.
value (float): The target value. Also see valueType.
isSynchronized (bool): If True, this target will be marked to be synchronized with other targets for which this parameter is True.
maxVelocity (float): Maximum velocity used for planning the motion. If not provided, setting in the vcJointDriver will be used.
maxAcceleration (float): Maximum acceleration used for planning the motion. If not provided, setting in the vcJointDriver will be used.
maxDeceleration (float): Maximum deceleration used for planning the motion. If not provided, setting in the vcJointDriver will be used. The value must be positive.
maxJerk (float): Maximum jerk used for planning the motion. If not provided, setting in the vcJointDriver will be used.

Returns:
(int): targetId assigned to the target. If the given targetId was positive, this will always be the same value.

Exceptions:
ValueError: When targetId is a negative value.
checkDriverValueLimitsBooleanNoneVerifies that all internal and external vcJointDrivers in this vcMotionController
See more
fall within their current min and max (position) value limits.
If this is true, or there are no such drivers, it returns true. Otherwise, returns false.

Returns:
bool: True if all drivers fall within their limits, False otherwise.
clearTargetsNoneNoneIf there are any queued vcMotionControllerTargets, clears them for the queue.
createDrivervcJointDriverString nameCreates a new driver and adds it to this controller's internal drivers collection.
See more
Parameters:
name (str): A name for the driver. Must be unique among all internal drivers in this controller.

Returns:
vcJointDriver: The newly created driver.

Exceptions:
ValueError: When given name is empty or a driver with the same name already exists.
RuntimeError: when driver can't be created e.g. due to connected export interface.
createGroupvcControllerGroupOptional Keyword[name = String]Creates a group into this controller, then returns a reference to the created group.
See more
The name is set if given, otherwise a free name will be assigned.

Parameters:
name (str): An optional name to set for the new group.

Returns:
vcControllerGroup: The created group.
deleteGroupNoneString groupNameDeletes the group from this controller. Also see vcControllerGroup.delete().
See more
Parameters:
groupName (str): The name of the group to delete.

Exceptions:
ValueError: When a group with the given name cannot be found.
getNearestValueslist[Real]List[Real] targetValues,
List[Real] referenceValues,
Boolean respectLimits
A helper method for adjusting full driver rotations so that the end results are as close to the given reference values as possible.
See more
This will only ever apply +/- 360 degrees steps, even if vcJointDriver.TurnSpan has another value.
If vcJointDriver.TurnSpan is zero, this method has no effect on that driver.

Parameters:
targetValues (list[float]): The desired values in any revolution. For example, results of vcKinSolver.inverse().
referenceValues (list[float]): Reference values guide turn selection. For example, last known internal driver values.
respectLimits (bool): If True, solution outside driver limits are not accepted.

Exceptions:
RuntimeError: When respectLimits was true and the method couldn't converge on good values.

Returns:
list[float]: Nearest values.
moveCoordinatedBooleanNoneThis method should be called after adding one or more coordinated targets (see addCoordinatedTarget). This will make sure that motion execution is
See more
ongoing and will trigger motion planning if the next coordinated target can be started immediately. If motion is already ongoing and cannot be
interrupted at this time, planning the next motion will happen when the current motion finishes or enters its blending zone.

This method is non-blocking. If you want to know when the motion completes, start awaiting for the OnTargetStatusChanged event
before calling this method.

Returns:
bool: True on success, false on error.
moveIndependentIntegerNoneThis call plans and starts all independent motions added since the last call to this method. Also see addIndependentMotion.
See more
This method is non-blocking. If you want to know when the motion completes, start awaiting for the OnTargetStatusChanged event
before calling this method.

Returns:
int: Number of planned targets on success.

Exceptions:
ValueError: When motion planning failed.
resumeNoneNoneResumes motion if it was stopped.

Parameters:
None

Returns:
None
setToolCenterPointtuple[Boolean, list[vcJointDriver]]vcMatrix newPosition,
vcMotionCoordinateSystem coordinateSystem,
Boolean pickNearestTurns,
Boolean respectLimits,
vcRobotConfiguration desiredConfiguration
An advanced setter for current tool center point position.
See more
Parameters:
newPosition (vcMatrix): The position to set.
coordinateSystem (vcMotionCoordinateSystem): The coordinate system to use when setting the position.
pickNearestTurns (bool): If True, turn handling is invoked.
respectLimits (bool): If True, driver limits are respected.
desiredConfiguration (vcMotionConfiguration): The desired configuration to attain when setting the position.

Exceptions:
RuntimeError: When respectLimits was true and the method couldn't converge on good values.

Returns:
(bool, list[vcJointDriver]): A boolean True if the position was reachable and a list of drivers that went out of limits, if any.
stopBooleanNoneStops all movement (immediate) without clearing the target / motion queue.
See more
Resume motion by calling resume(), moveIndependent() or moveCoordinated().

Parameters:
None

Returns:
bool: True on success.
testExternalDriverValueLimitslist[vcJointDriver]List[tuple[Integer, Real]] valuesTests which external drivers would be outside their (position) value limits if the given values were applied to them.
See more
This method doesn't assign the values to the drivers, it only tests them.

Parameters:
values (list[tuple(int, float)]): Applies the given values based on index value 2-tuples.

Returns:
list[vcJointDriver]: List of drivers outside of limits.

Exceptions:
IndexError: When values contain one or more invalid index.
testInternalDriverValueLimitslist[vcJointDriver]List[Real] valuesTests which internal drivers would be outside their (position) value limits if the given values were applied to them.
See more
This method doesn't assign the values to the drivers, it only tests them.

Parameters:
values (list[float]): Applies the given values starting from index 0.

Returns:
list[vcJointDriver]: List of drivers outside of limits.

Exceptions:
IndexError: When values has excessive number of values.
testInternalDriverValueLimitslist[vcJointDriver]List[tuple[Integer, Real]] valuesTests which internal drivers would be outside their (position) value limits if the given values were applied to them.
See more
This method doesn't assign the values to the drivers, it only tests them.

Parameters:
values (list[tuple(int, float)]): Applies the given values based on index value 2-tuples.

Returns:
list[vcJointDriver]: List of drivers outside of limits.

Exceptions:
IndexError: When values contain one or more invalid index.
waitUntilTargetsReachedobjectOptional[List[Integer] targetIds],
Optional Keyword[timeout = Real]
Blocks script execution until given targets are reached.

This function returns an awaitable task. It must be awaited.
See more
If no targetIds are specified, the awaitable is done when the next motion has fully completed, i.e.,
a target has been reached exactly.

If one or more targetIds are specified, the awaitable is done when all of those motions have finished
or failed, or have been cancelled.

Parameters:
targetIds list[int]: An optional list of target ids of the motions to monitor.
timeout [float]: An optional time out value, in seconds.

Returns:
Awaitable[Tuple]: The task instance. When awaited returns a list of tuples, where the tuples are received OnStatusChanged event arguments,
in the order they were raised in.

Events

Learn how to use events here. The events are also inherited from the parent class.

NameParametersDescription
OnGroupAddedvcControllerGroup groupTriggered when a new controller group is created in this controller.

Parameters:
group (vcRobotics2.vcControllerGroup): new group.
OnGroupRemovedNoneTriggered when a controller group has been deleted from this controller.
OnPositionUpdatedvcMotionController controllerTriggered when controller updated the robot's state e.g. driver positions

Parameters:
controller (vcMotionController): Sender.
OnTargetStatusChangedvcMotionController controller,
vcTargetStatusChangedEventType eventType,
int targetId
Triggered when a notable event happens in a programmed motion, e.g. the motion has been finished.
See more
Parameters:
controller (vcMotionController): Sender.
eventType (vcTargetStatusChangedEventType): Defines what kind of event happened.
targetId (int): Matches the targetId value of the vcMotionTarget that was used to plan this motion.

Example: Robot Pose to Target

from vcCore import *
from vcFeatures import *
from vcGeometry import *
from vcBehaviors import *
from vcRobotics2 import *

def robot_pose_to_target(controller: vcMotionController, type: vcMotionTargetType, toolName="Null", baseName="Null") -> vcLinearTarget | vcPtpTarget | vcMultiDriverTarget:
  """Compile robot target from curen robot position, based on motion target type, tool and base data. (Excludes speed data)"""

  # Controller driver positions
  internalDriverPositions = controller.DriverPositions
  externalDriverPositions = controller.ExternalDriverPositions

  # Joint target does not require solving
  if type == vcMotionTargetType.MULTIDRIVER:
    target: vcMultiDriverTarget = controller.createTarget(type)
    target.InternalDriverValues = [(i, val) for i, val in enumerate(internalDriverPositions)]
    target.ExternalDriverValues = externalDriverPositions
    return target

  # Cartesian targets require use of kinematic solver
  if type == vcMotionTargetType.LINEAR or vcMotionTargetType.PTP:
    
    # Kinematics object for controller
    kinematics = controller.Kinematics

    # Create solver for calculating forward kinematic solution for pose
    solver = kinematics.createSolver()
    
    # Define all forvard solution related information
    solver.RootMatrix = controller.Component.WorldPositionMatrix
    solver.BaseMatrix = kinematics.findBase(baseName).PositionMatrix
    solver.ToolMatrix = kinematics.findTool(toolName).PositionMatrix
    
    # Fill in preoperties based on target type
    target: vcLinearTarget | vcPtpTarget = controller.createTarget(type)
    target.Target = solver.forward(internalDriverPositions)
    if isinstance(target, vcLinearTarget):
      target.InternalDriverValues = internalDriverPositions
    if isinstance(target, vcPtpTarget):
      target.DriverReferenceValues = internalDriverPositions
    target.ExternalDriverValues = externalDriverPositions
    
    return target
# Snippet ------------------------------------

def OnReset():
  controller: vcMotionController = getComponent().findBehaviorsByType(vcBehaviorType.ROBOTICS2_MOTIONCONTROLLER)[0]
  target = robotPoseToTarget(controller, vcMotionTargetType.LINEAR, "TOOL[1]", "BASE_2")

Example: Get Pose Configuration

from vcCore import *
from vcFeatures import *
from vcGeometry import *
from vcBehaviors import *

from vcRobotics2 import *


# Snippet ------------------------------------
def get_pose_configuration(controller: vcMotionController, target: vcLinearTarget | vcPtpTarget | vcMultiDriverTarget):
  """Gets the solved driverConfiguration information value for a target defined in cartesian format"""
  
  # create solver for calculating configuration based on driver values
  solver = controller.Kinematics.createSolver()
  
  # values for robots joints
  if isinstance(target, vcMultiDriverTarget):
    internalDriverValues = [val[1] for val in target.InternalDriverValues]
  if isinstance(target, vcLinearTarget):
    internalDriverValues = target.InternalDriverValues
  if isinstance(target, vcPtpTarget):
    internalDriverValues = target.DriverReferenceValues

  # Solve objects value and description. example: ('FRONT BELOW NOFLIP', 1)
  configurationObject = solver.getConfiguration(internalDriverValues)
  configEnumProperty: vcIntEnumProperty = configurationObject.Properties[0]
  description = configEnumProperty.ValueDescription
  value = configEnumProperty.Value
  
  return description, value
# Snippet ------------------------------------


def OnReset():
  controller: vcMotionController = getComponent().findBehaviorsByType(vcBehaviorType.ROBOTICS2_MOTIONCONTROLLER)[0]
  solver = controller.Kinematics.createSolver()  
  mat = solver.forward(controller.DriverPositions)
  target: vcLinearTarget = controller.createTarget(vcMotionTargetType.LINEAR)
  target.Target = mat
  target.InternalDriverValues = controller.DriverPositions
  print(target.Target)
  print(getPoseConfiguration(controller, target))